﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ausm.ObjectStore.Example.Entities;
using Ausm.ObjectStore.Example.Wrapper;
using Ausm.ObjectStore.OrMapping;

namespace Ausm.ObjectStore.Example
{
    class Program
    {
        static void Main(string[] args)
        {
            CreateDatabase.GenerateDataBase();

            ObjectStoreManager.DefaultObjectStore.RegisterObjectProvider(new RelationalObjectStore("default", true));

            Person person = ObjectStoreManager.DefaultObjectStore.CreateObject<Person>();
            person.Name = "Person1";

            Address address = ObjectStoreManager.DefaultObjectStore.CreateObject<Address>();
            address.Person = person;
            address.Street = "First Street 15";
            address.ZipCode = 123456;
            address.City = "Gotham";

            ObjectStoreManager.DefaultObjectStore.GetQueryable<Person>().Save();

            IQueryable<PersonWrapper> wrapperQuery = ObjectStoreManager.DefaultObjectStore.GetQueryable<Person>().Select(x => new PersonWrapper(x));

            foreach (PersonWrapper wrapper in wrapperQuery)
            {
                Console.WriteLine(wrapper);
            }

            ObjectStoreManager.DefaultObjectStore.GetQueryable<Person>().Delete();
            ObjectStoreManager.DefaultObjectStore.GetQueryable<Person>().Save();
        }
    }
}
